package business;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import views.MainFrame;

public class WPDesktop extends JDesktopPane{
    private Image wallPaper;
    public WPDesktop(Image wallPaper) {
        this.wallPaper = wallPaper;
        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(wallPaper, 0);
        try {
            tracker.waitForAll();
        } catch (InterruptedException e) {
          //  System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

    public WPDesktop() {
    }

    public void initBack() {
        Toolkit tk=Toolkit.getDefaultToolkit();
        Image bg = tk.getImage("image/sale.jpg");
        JDesktopPane desktop = new WPDesktop(bg);
        JInternalFrame childFrame = new JInternalFrame("MDI child frame", true);
        childFrame.setBounds(100, 100, 200, 200);
        desktop.add(childFrame, new Integer(10));
        childFrame.show();
        MainFrame main = new MainFrame();
        main.getContentPane().add(desktop);
        main.pack();
        main.setVisible(true);
    }

    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        int width = wallPaper.getWidth(this);
        int height = wallPaper.getHeight(this);
        Dimension size = getSize(); // paint tiled wall paper
        for (int x = 0; x < size.width; x += width)
            for (int y = 0; y < size.height; y += height)
                g.drawImage(wallPaper, x, y, this);
    }
     public Dimension getPreferredSize()
     {
         return new Dimension(wallPaper.getWidth(this),
                              wallPaper.getHeight(this));
     }
}
